package writtenexamination.weimeng.mianshi;

import java.util.ArrayList;
import java.util.Collections;

/**
 * @author cyt
 * @create 2020-10-24 下午 7:32
 */
public class Tc {
    public int getRepeatCharLength(String str) {
        // write code here
        ArrayList<String> list = new ArrayList<>();
        for (int i = str.length() - 1; i >= 0; i--) {
            list.add(str.substring(i));
        }
        Collections.sort(list);
        int maxlen = 0;
        for (int i = 0; i < str.length() - 1; i++) {
            int len = getComlen(list.get(i), list.get(i + 1));
            maxlen = Math.max(len, maxlen);
        }
        return result.length();
    }

    String result = "";

    public int getComlen(String str1, String str2) {
        int i;
        for (i = 0; i < str1.length() && i < str2.length(); i++) {
            if (str1.charAt(i) != str2.charAt(i)) {
                break;
            }
        }
        String temp = str1.substring(0, i);
        if (temp.length() > result.length()) {
            result = temp;
        }
        return i;
    }
}
